/**
 * @(#) DataCompoment.java
 */

package cn.edu.sjtu.se.dslab.component.data;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import cn.edu.sjtu.se.dslab.component.Component;

@Entity
@Table(name = "data_component")
@PrimaryKeyJoinColumn(name = "id")
public class DataComponent extends Component {
	private static final long serialVersionUID = 1L;

	private Set<DataComponent> depends;

	private Set<DataComponent> childList;

	/**
	 * 结构体定义(如果有实现代码，定义文件和实现文件用分号隔开，先是定义代码)
	 */
	private String filepath;

	private DomainEntity entity;

	@Column(name = "filepath", nullable = true, length = 1000)
	public String getFilepath() {
		return filepath;
	}

	public void setFilepath(String filepath) {
		this.filepath = filepath;
	}

	// 多对多处理
	@ManyToMany(targetEntity = cn.edu.sjtu.se.dslab.component.data.DataComponent.class, cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinTable(name = "data_dependence", joinColumns = @JoinColumn(name = "child_id"), inverseJoinColumns = @JoinColumn(name = "parent_id"))
	public Set<DataComponent> getDepends() {
		return depends;
	}

	public void setDepends(Set<DataComponent> depends) {
		this.depends = depends;
	}

	@ManyToMany(cascade = { CascadeType.ALL }, mappedBy = "depends", targetEntity = cn.edu.sjtu.se.dslab.component.data.DataComponent.class, fetch = FetchType.EAGER)
	public Set<DataComponent> getChildList() {
		return childList;
	}

	public void setChildList(Set<DataComponent> childList) {
		this.childList = childList;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "entity_id")
	public DomainEntity getEntity() {
		return entity;
	}

	public void setEntity(DomainEntity entity) {
		this.entity = entity;
	}

}
